package com.xianyu.admin.common;

import com.xianyu.admin.common.Result;
import com.xianyu.admin.common.ResultCode;

/**
* 响应结果生成工具
* 作者:羡鱼
* qq:642133706
* 当前时间 2024/8/31 7:56
*/
public class ResultGenerator {
    private static final String DEFAULT_SUCCESS_MESSAGE = "SUCCESS";

    public static Result genSuccessResult() {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE);
    }

    public static <T> Result genSuccessResult(T data) {
        return new Result()
                .setCode(ResultCode.SUCCESS)
                .setMessage(DEFAULT_SUCCESS_MESSAGE)
                .setData(data);
    }

    public static Result genFailResult(String message) {
        return new Result()
                .setCode(ResultCode.FAIL)
                .setMessage(message);
    }

    public static Result genResult(ResultCode code, String message) {
        return new Result()
                .setCode(code)
                .setMessage(message);
    }
}
